<html><head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
   <title>The Object-Graph Navigation Language(OGNL)</title><link rel="stylesheet" type="text/css" href="eclipse_book.css"><meta name="generator" content="DocBook XSL Stylesheets V1.77.1"><link rel="home" href="index.html" title="Red Hat Fuse Tooling"><link rel="up" href="RiderExLang.html" title="Part&nbsp;III.&nbsp;Expression and Predicates Languages"><link rel="prev" href="MVEL.html" title="MVEL"><link rel="next" href="PHP.html" title="PHP (DEPRECATED)"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a name="OGNL"></a>The Object-Graph Navigation Language(OGNL)</h2></div></div></div><div class="simplesect"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="topic-33440"></a>Overview</h2></div></div></div><p>OGNL is an expression language for
getting and setting properties of Java objects. You use the same expression for both getting
and setting the value of a property. The OGNL support is in the <code class="literal">camel-ognl</code>
module.</p></div><div class="simplesect"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_camel_on_eap_deployment_2"></a>Camel on EAP deployment</h2></div></div></div><p>This component is supported by the Camel on EAP (Wildfly Camel) framework, which
offers a simplified deployment model on the Red Hat JBoss Enterprise Application Platform (JBoss EAP) container.</p></div><div class="simplesect"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="topic-33441"></a>Adding the OGNL module</h2></div></div></div><p>To use OGNL in your routes you need to add a dependency on
<code class="literal">camel-ognl</code> to your project as shown in
<a class="xref" href="OGNL.html#ExPredLangOGNLEx060" title="Example&nbsp;11.&nbsp;Adding the camel-ognl dependency">Example&nbsp;11, &#8220;Adding the camel-ognl dependency&#8221;</a>.</p><div class="example"><a name="ExPredLangOGNLEx060"></a><p class="title"><b>Example&nbsp;11.&nbsp;Adding the camel-ognl dependency</b></p><div class="example-contents"><pre class="screen">&lt;!-- Maven POM File --&gt;
...
&lt;dependencies&gt;
  ...
  &lt;dependency&gt;
    &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
    &lt;artifactId&gt;camel-ognl&lt;/artifactId&gt;
    &lt;version&gt;${camel-version}&lt;/version&gt;
  &lt;/dependency&gt;
  ...
&lt;/dependencies&gt;</pre></div></div><br class="example-break"></div><div class="simplesect"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="topic-33442"></a>Static import</h2></div></div></div><p>To use the <code class="literal">ognl()</code> static method in your application code, include
the following import statement in your Java source files:</p><pre class="screen">import static org.apache.camel.language.ognl.OgnlExpression.ognl;</pre></div><div class="simplesect"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="topic-33443"></a>Built-in variables</h2></div></div></div><p><a class="xref" href="OGNL.html#OGNLAttTbl010" title="Table&nbsp;12.&nbsp;OGNL variables">Table&nbsp;12, &#8220;OGNL variables&#8221;</a> lists the built-in variables that are accessible
when using OGNL.</p><div class="table"><a name="OGNLAttTbl010"></a><p class="title"><b>Table&nbsp;12.&nbsp;OGNL variables</b></p><div class="table-contents"><table summary="OGNL variables" border="1"><colgroup><col width="33%" class="col_1"><col width="33%" class="col_2"><col width="34%" class="col_3"></colgroup><thead><tr><th align="left" valign="top">Name</th><th align="left" valign="top">Type</th><th align="left" valign="top">Description</th></tr></thead><tbody><tr><td align="left" valign="top"><p><code class="literal">this</code></p></td><td align="left" valign="top"><p><code class="literal">org.apache.camel.Exchange</code></p></td><td align="left" valign="top"><p>The current Exchange</p></td></tr><tr><td align="left" valign="top"><p><code class="literal">exchange</code></p></td><td align="left" valign="top"><p><code class="literal">org.apache.camel.Exchange</code></p></td><td align="left" valign="top"><p>The current Exchange</p></td></tr><tr><td align="left" valign="top"><p><code class="literal">exception</code></p></td><td align="left" valign="top"><p><code class="literal">Throwable</code></p></td><td align="left" valign="top"><p>the Exchange exception (if any)</p></td></tr><tr><td align="left" valign="top"><p><code class="literal">exchangeID</code></p></td><td align="left" valign="top"><p><code class="literal">String</code></p></td><td align="left" valign="top"><p>the Exchange ID</p></td></tr><tr><td align="left" valign="top"><p><code class="literal">fault</code></p></td><td align="left" valign="top"><p><code class="literal">org.apache.camel.Message</code></p></td><td align="left" valign="top"><p>The Fault message(if any)</p></td></tr><tr><td align="left" valign="top"><p><code class="literal">request</code></p></td><td align="left" valign="top"><p><code class="literal">org.apache.camel.Message</code></p></td><td align="left" valign="top"><p>The IN message</p></td></tr><tr><td align="left" valign="top"><p><code class="literal">response</code></p></td><td align="left" valign="top"><p><code class="literal">org.apache.camel.Message</code></p></td><td align="left" valign="top"><p>The OUT message</p></td></tr><tr><td align="left" valign="top"><p><code class="literal">properties</code></p></td><td align="left" valign="top"><p><code class="literal">Map</code></p></td><td align="left" valign="top"><p>The Exchange properties</p></td></tr><tr><td align="left" valign="top"><p><code class="literal">property(<span class="emphasis"><em>name</em></span>)</code></p></td><td align="left" valign="top"><p><code class="literal">Object</code></p></td><td align="left" valign="top"><p>The value of the named Exchange property</p></td></tr><tr><td align="left" valign="top"><p><code class="literal">property(<span class="emphasis"><em>name</em></span>, <span class="emphasis"><em>type</em></span>)</code></p></td><td align="left" valign="top"><p><code class="literal"><span class="emphasis"><em>Type</em></span></code></p></td><td align="left" valign="top"><p>The typed value of the named Exchange property</p></td></tr></tbody></table></div></div><br class="table-break"></div><div class="simplesect"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="topic-33444"></a>Example</h2></div></div></div><p><a class="xref" href="OGNL.html#ExPredLangOGNLEx090" title="Example&nbsp;12.&nbsp;Route using OGNL">Example&nbsp;12, &#8220;Route using OGNL&#8221;</a> shows a route that uses OGNL.</p><div class="example"><a name="ExPredLangOGNLEx090"></a><p class="title"><b>Example&nbsp;12.&nbsp;Route using OGNL</b></p><div class="example-contents"><pre class="screen">&lt;camelContext&gt;
  &lt;route&gt;
    &lt;from uri="seda:foo"/&gt;
    &lt;filter&gt;
      &lt;language langauge="ognl"&gt;request.headers.foo == 'bar'&lt;/language&gt;
      &lt;to uri="seda:bar"/&gt;
    &lt;/filter&gt;
  &lt;/route&gt;
&lt;/camelContext&gt;</pre></div></div><br class="example-break"></div></div></body></html>